package spring.cloud.tasks.api.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import spring.cloud.tasks.api.service.AlarmStatisticsService;
import spring.cloud.tasks.api.utils.Response;

import javax.annotation.Resource;

/**
 * 域的告警统计
 *
 * @author hebelala
 */
@RequestMapping("/api/namespaces/{namespace:.+}/alarmStatistics")
public class NamespaceAlarmStatisticsController {

    @Resource
    private AlarmStatisticsService alarmStatisticsService;

    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/abnormalJobs")
    public Response getAbnormalJobs(@PathVariable String namespace)
            throws RuntimeException {
        return Response.success(alarmStatisticsService.getAbnormalJobsStringByNamespace(namespace));
    }

    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/unableFailoverJobs")
    public Response getUnableFailoverJobs(@PathVariable String namespace)
            throws RuntimeException {
        return Response.success(alarmStatisticsService.getUnableFailoverJobsStringByNamespace(namespace));
    }

    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/timeout4AlarmJobs")
    public Response getTimeout4AlarmJobs(@PathVariable String namespace)
            throws RuntimeException {
        return Response.success(alarmStatisticsService.getTimeout4AlarmJobsStringByNamespace(namespace));
    }


    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/countOfAlarmJobs")
    public Response getCountOfAlarmJobs(@PathVariable String namespace)
            throws RuntimeException {
        return Response.success(alarmStatisticsService.getCountOfAlarmJobsByNamespace(namespace));
    }

    //@ApiResponses(value = {@ApiResponse(code = 200, message = "Success/Fail", response = RequestResult.class)})
    @GetMapping(value = "/abnormalContainers")
    public Response getAbnormalContainers(@PathVariable String namespace)
            throws RuntimeException {
        return Response.success(alarmStatisticsService.getAbnormalContainersByNamespace(namespace));
    }

}
